﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF ( OBJECT_ID(N'[dbo].[sproc_Mail_GetSMSToSend]', 'P') IS NOT NULL )
BEGIN
    DROP PROCEDURE [dbo].[sproc_Mail_GetSMSToSend]
END
GO
CREATE PROCEDURE [dbo].[sproc_Mail_GetSMSToSend]
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;

SELECT TOP 10
	m.MailId,
	s1.RealName as Receiver,
	s1.Mobile as ReceiverPhone,
	s2.RealName as Sender,
	mb.Body
FROM dbo.UDS_Mail m
	INNER JOIN dbo.UDS_Staff s1 ON m.UserName = s1.Staff_Name
	INNER JOIN dbo.UDS_MailBody mb ON m.MailBodyId = mb.MailBodyId
	INNER JOIN dbo.UDS_Staff s2 ON mb.Creator = s2.Staff_Name
WHERE m.SMSFlag = 1
ORDER BY m.TimeCreated ASC;

END
GO
